<{include file="Public/head.tpl"}>
<{include file="Public/header.tpl"}>
<{include file="Public/siderbar.tpl"}>
<{include file="Public/contentheader.tpl"}>

    <!-- Main content -->
    <section class="content">

      <div class="col-md-8">
        <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">请填写新权限的信息</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
              <div class="box-body">
                <div class="form-group">
                  <label for="type" class="col-sm-2 control-label">上级</label>
                  <div class="col-sm-10">
                    <select class="form-control" id="parentid">
                      <option value="0">作为一级菜单</option>
                      <{$power}>
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <label for="title" class="col-sm-2 control-label">权限名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="title" placeholder="权限名">
                  </div>
                </div>
                <div class="form-group">
                  <label for="controller" class="col-sm-2 control-label">控制器</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="controller" placeholder="控制器">
                  </div>
                </div>
                <div class="form-group">
                  <label for="action" class="col-sm-2 control-label">方法</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="action" placeholder="方法，默认是index">
                  </div>
                </div>
                <div class="form-group">
                  <label for="priority" class="col-sm-2 control-label">排序值</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="priority" placeholder="排序值，默认是0">
                  </div>
                </div>
                <div class="form-group">
                  <label for="type" class="col-sm-2 control-label">类型</label>
                  <div class="col-sm-10">
                    <select class="form-control" id="type">
                      <option value="1">权限+菜单</option>
                      <option value="2">仅权限</option>
                      <option value="3">仅菜单</option>
                    </select>
                  </div>
                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <a href="/admin/power/list" class="btn btn-default">取消</a>
                <button type="button" class="btn btn-info pull-right" onclick="add();">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
       </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
<{include file="Public/footer.tpl"}>
<script>
    function add() {
      bootbox.setLocale("zh_CN");
	    var posturl = window.location.href;
      var parentid = document.getElementById("parentid").value;
      var title = document.getElementById("title").value;
      var controller = document.getElementById("controller").value;
      var action = document.getElementById("action").value;
      var priority = document.getElementById("priority").value;
      var type = document.getElementById("type").value;
  
      if (parentid == ''){
        bootbox.alert("上级不能为空"); 
        return;
      }
      if (title == ''){
        bootbox.alert("权限名不能为空"); 
        return;
      }
      if (controller == ''){
        bootbox.alert("控制器不能为空");
        return;
      }
      if (action == ''){
        action = 'index';
      }
      if (priority == ''){
        priority = 0;
      }
      if (type == ''){
        bootbox.alert("类型不能为空");
        return;
      }
  
      $.ajax({
        url : posturl,
        type : 'post',
        data : 'parentid=' + parentid
            + '&title=' + title
            + '&controller=' + controller
            + '&action=' + action
            + '&priority=' + priority
            + '&type=' + type,
        success : function(data) {
          var ret = JSON.parse(data);
          if (ret.status == 1) {
            bootbox.alert(ret.data);
            setTimeout(function(){window.location.href="/admin/power/list"}, 2000);
          } else {
            bootbox.alert(ret.data);
          }
        }
      });
    }
</script>
</body>
</html>